//
//  FontAwesomeViewController.m
//  Example
//
//  Created by admin on 2020/4/15.
//  Copyright © 2020 admin. All rights reserved.
//

#import "FontAwesomeViewController.h"

@interface FontAwesomeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property(strong, nonatomic) UICollectionView * collectionView;
@property(strong, nonatomic) NSMutableDictionary * datadic;
@end

@implementation FontAwesomeViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    [self configUI];
}

-(void)configUI{
    self.title = @"FontAwesome";
    [self.view addSubview:self.collectionView];
}
-(void)loadData{
    self.datadic = [[NSString enumDictionary] copy];
}

-(UICollectionView *)collectionView{

    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.minimumLineSpacing = 0.f;
        flowLayout.minimumInteritemSpacing = 0.f;
        flowLayout.itemSize = CGSizeMake(KWidth, 120);
        flowLayout.headerReferenceSize = CGSizeZero;
        flowLayout.footerReferenceSize = CGSizeZero;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = UIColor.whiteColor;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.scrollsToTop = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        [_collectionView registerClass:[DefualCollectionViewCell class] forCellWithReuseIdentifier:@"DefualCollectionViewCell"];

        
    }
    return _collectionView;
}

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

#pragma mark collectionView

- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    DefualCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DefualCollectionViewCell" forIndexPath:indexPath];
    NSString *key = [_datadic.allKeys objectAtIndex:indexPath.row];
    
    
    cell.backgroundColor = UIColor.whiteColor;
    [cell ug_borderColor:COLORINFO width:0.5];
    cell.titleLab.textColor = COLORINFO;
    cell.imageView.contentMode = UIViewContentModeCenter;
    [cell.button setImage:[UIImage imageWithIcon:key backgroundColor:UIColor.whiteColor iconColor:COLORDANGER andSize:CGSizeMake(24, 24)] forState:UIControlStateNormal];
    [cell.button setTitle:key forState:UIControlStateNormal];
    return cell;
    
}

- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return _datadic.allKeys.count;;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(KWidth/4, KWidth/4);
    
}

@end
